/**
 * 按钮加载动作
 */
"use strict";


var button = function(opt) {
	this.option = opt;
};

/**
 * 
 * Button start loading
 * */
button.prototype.load = function(opt) {

	var options = {
		elem: opt.elem,
		time: opt.time ? opt.time : false,
		done: opt.done ? opt.done : function() { }
	}

	var text = $(options.elem).html();

	$(options.elem).html('<span class="spinner-border spinner-border-sm"></span>');
	$(options.elem).attr("disabled", "disabled");

	var $button = $(options.elem);

	if (options.time != "" || options.time != false) {
		setTimeout(function() {
			$button.attr("disabled", false);
			$button.html(text);
			options.done();
		}, options.time);
	}
	options.text = text;
	return new button(options);
}

/**
 * 
 * Button stop loaded
 * */
button.prototype.stop = function(success) {
	$(this.option.elem).attr("disabled", false);
	$(this.option.elem).html(this.option.text);
	$(this.option.elem).removeClass("sp sp-circle")
	success && success();
}

export default new button();